/**
 * 
 */
package dao;

import java.sql.SQLException;

import utils.Const;
import com.j256.ormlite.dao.Dao;
import database.DatabaseHelper;
import entity.Plan;
import entity.Transaction;

/**
 * @author Hung
 *
 */
public class TransactionDAO {
	
	private Dao<Transaction, Integer> dao = null;
	
	public TransactionDAO(DatabaseHelper helper) throws Exception {
		dao = helper.getTransactionDao();
		if (dao == null)
			throw new Exception(Const.NULL_DAO_ERROR);
	}
	
	public int createTransaction(Transaction transaction) throws SQLException {
		return dao.create(transaction);
	}
	
	public int updateTransaction(Transaction transaction) throws SQLException {
		return dao.update(transaction);
	}
	
	public int deleteTransaction(Transaction transaction) throws SQLException {
		return dao.delete(transaction);
	}
	
	public Transaction getTransactionById(int id) throws SQLException {
		return dao.queryForId(id);
	}
}
